<html>
	<head><title>Add Regions</title></head>
	<body>
		
		<center><h1><Regions></h1></center>	
		<?php
			$con = mysql_connect("oniddb.cws.oregonstate.edu","rundej-db","Hp2tYI0CxEY4U9J9");
			if (!$con)
			{
				die('Could not connect: ' . mysql_error());
			}
			mysql_select_db('rundej-db',$con);	

			if(!($_POST["regionNo"]) || !($_POST["regionName"]))
			{
				echo "<center><h1>You didn't enter a region!</center></h1>";
			}
			else
			{
				$num = $_POST["regionNo"];
				$rname = $_POST["regionName"];
				$head = $_POST["headquarters"];
				$pres = $_POST["presName"];
				mysql_query("INSERT INTO Region(Region_No,Region_Name,Headquarters,President_Name) VALUES('".$num."','".$rname."','".$head."','".$pres."');",$con);
				echo "<center><h2>" . "The " . $_POST["regionName"] . " Region has been successfully added!</h2><br>";
				echo "Region No.: " . $_POST["regionNo"] . "<br>";
				echo "Region Name: " . $_POST["regionName"] . "<br>";
				echo "Captain Name: " . $_POST["captainName"] . "<br>";
				echo "Headquarters: " . $_POST["headquarters"] . "<br>";
				echo "President: " . $_POST["presName"] . "<br></center>";
			}
		?>
		
		<br>
		<center>	
		<table border="1">
		<tr>
			<th>Region No.</th>
			<th>Region Name</th>
			<th>Captain No.</th>
			<th>Headquarters</th>
			<th>President Name</th>
			<th>Wins</th>
			<th>Losses</th>
			<th>Ties</th>
		</tr>
		<?php
			$result = mysql_query("SELECT * FROM Region");
			while ($row = mysql_fetch_array($result))
			{
				echo "<tr>";
				echo "<td>" . $row['Region_No'] . "</td>";
				echo "<td>" . $row['Region_Name'] . "</td>";
				echo "<td>" . $row['Captain'] . "</td>";
				echo "<td>" . $row['Headquarters'] . "</td>";
				echo "<td>" . $row['President_Name'] . "</td>";
				echo "<td>" . $row['Num_Wins'] . "</td>";
				echo "<td>" . $row['Num_Losses'] . "</td>";
				echo "<td>" . $row['Num_Ties'] . "</td>";
				echo "</tr>";
			}
			mysql_close($con);
		?>
		</table>
		<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/">Back to Home</a>
		<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/regions.php">Back to Regions</a>
		<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/umpires.php">Umpires</a>
		<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/players.php">Players</a>
		</center>	
	</body>
</html>
